<template>
  <div class="template-main">
    <NavigationBarBack title="新建模板" />
    <div class="create-template-wrap">
      <div class="config-box">
        <el-form ref="form" :model="form" label-width="120px" class="new-fan-body" label-position="left">
          <div class="config-settig-card">
            <div class="card-head">
              <div class="card-title">基本设置</div>
            </div>
            <div class="card-body">
              <el-form-item label="模板名称：">
                <el-input v-model="form.modelName" size="small" style="width: 300px;" />
              </el-form-item>
              <el-form-item label="模板类型：">
                <div class="mode-type-list">
                  <div :class="['mode-item', item.type === form.type && 'active']" v-for="(item, index) in modeList" :key="index"
                    @click="onHandleCheckModeItem(item.type)">
                    <div class="type-icon">
                      <svg-icon :icon-class="item.icon" class-name="icon" />
                    </div>
                    <div class="type-title">{{ item.title }}</div>
                    <div class="type-context">{{ item.desc }}</div>
                  </div>
                </div>
              </el-form-item>
              <el-form-item label="消息退订：">
                <el-switch size="small" v-model="form.switch" />
              </el-form-item>
            </div>
          </div>
          <div class="config-settig-card">
            <div class="card-head">
              <div class="card-title">发送计划</div>
              <el-button size="small" plain style="margin-right: 24px;" @click="showDialog = true">批量设置时间间隔</el-button>
            </div>
            <div class="card-body">
              <div class="plan-container">
                <div class="plan-left">
                  <el-button class="plus-btn" plain type="primary" icon="el-icon-plus">添加一天任务</el-button>
                  <div class="sop-dov-item active">
                    <span>第1天</span>
                    <div class="btns">
                      <i class="el-icon-document-copy"></i>
                    </div>
                  </div>
                </div>
                <div class="plan-right">
                  <div class="plan-right-top">
                    <div class="top-flex-rows" v-if="form.type === 1">
                      第<el-input style="width: 66px;" size="small" />天
                      <el-radio-group size="small" v-model="form.radio1" style="margin-left: 16px;">
                        <el-radio-button :label="0">时间段随机发送</el-radio-button>
                        <el-radio-button :label="1">时间点精确发送</el-radio-button>
                      </el-radio-group>
                      <div v-if="form.radio1 === 0">
                        <el-time-picker is-range v-model="form.value1" range-separator="至" start-placeholder="开始时间"
                          end-placeholder="结束时间" placeholder="选择时间范围" size="small">
                        </el-time-picker>
                        <span style="color: rgb(102, 102, 102);">内随机开始发送第一条</span>
                      </div>
                    </div>
                    <div class="top-flex-column" v-if="form.type === 2">
                      <el-radio-group v-model="form.tagRadio">
                        <el-radio :label="0">
                          <div class="radio-item">
                            打上标签<el-input style="width: 48px;" size="small" />小时<el-input style="width: 48px;" size="small" />内随机开始发送首次任务
                          </div>
                        </el-radio>
                        <el-radio :label="1">
                          <div class="radio-item">
                            打上标签<el-input style="width: 48px;" size="small" />天后的
                            <el-time-picker is-range v-model="form.value1" range-separator="至" start-placeholder="开始时间"
                                end-placeholder="结束时间" placeholder="选择时间范围" size="small" style="width: 220px;">
                              </el-time-picker>
                            分后开始发送首次任务
                          </div>
                        </el-radio>
                        <el-radio :label="2">
                          <div class="radio-item">
                            指定时间<el-date-picker type="date"placeholder="选择日期"  style="width: 150px;"/>
                            <el-time-picker is-range v-model="form.value1" range-separator="至" start-placeholder="开始时间"
                                end-placeholder="结束时间" placeholder="选择时间范围" size="small" style="width: 220px;">
                              </el-time-picker>
                              开始发送首次任务
                          </div>
                        </el-radio>
                      </el-radio-group>
                    </div>
                    <div class="top-flex-column" v-if="form.type === 3">
                      <el-radio-group v-model="form.tagRadio">
                        <el-radio :label="0">
                          <div class="radio-item">
                            加为好友<el-input style="width: 48px;" size="small" />小时<el-input style="width: 48px;" size="small" />分后开始发送首次任务
                          </div>
                        </el-radio>
                        <el-radio :label="1">
                          <div class="radio-item">
                            加为好友<el-input style="width: 48px;" size="small" />天后的
                            <el-time-picker is-range v-model="form.value1" range-separator="至" start-placeholder="开始时间"
                                end-placeholder="结束时间" placeholder="选择时间范围" size="small" style="width: 220px;">
                              </el-time-picker>
                            内随机开始发送首次任务
                          </div>
                        </el-radio>
                      </el-radio-group>
                    </div>
                    <div class="top-flex-column" v-if="form.type === 4">
                      <el-radio-group v-model="form.tagRadio">
                        <el-radio :label="0">
                          <div class="radio-item">
                            群满足条件<el-input style="width: 48px;" size="small" />小时<el-input style="width: 48px;" size="small" />分后开始发送首次任务
                          </div>
                        </el-radio>
                        <el-radio :label="1">
                          <div class="radio-item">
                            指定时间<el-date-picker type="date"placeholder="选择日期"  style="width: 150px;"/>
                            <el-time-picker is-range v-model="form.value1" range-separator="至" start-placeholder="开始时间"
                                end-placeholder="结束时间" placeholder="选择时间范围" size="small" style="width: 220px;">
                              </el-time-picker>
                              开始发送首次任务
                          </div>
                        </el-radio>
                      </el-radio-group>
                    </div>
                  </div>
                  <div class="material-body">
                    <material-content ref="material" />
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-form>
      </div>
    </div>
    <ChangeSendTimeDialog :visableIf.sync="showDialog" />
  </div>
</template>
<script>
import MaterialContent from "@/components/MaterialContent";
import ChangeSendTimeDialog from '../components/changeSendTimeDialog' 
export default {
  data() {
    return {
      form: {
        modelName: '我的模板',
        radio1: 0,
        type: 1,
        tagRadio: 0,
        value1: [new Date(2016, 9, 10, 8, 40), new Date(2016, 9, 10, 9, 40)],
      },
      modeList: [
        { icon: 'sop-norm', title: '标准模板', desc: '手动创建SOP计划任务时调用', type: 1 },
        { icon: 'sop-tag', title: '标签SOP模板', desc: '创建标签SOP自动规则时调用', type: 2 },
        { icon: 'sop-customer', title: '新客户模板', desc: '创建新客户SOP自动规则时调用', type: 3 },
        { icon: 'sop-group', title: '群模板', desc: '创建群SOP自动规则时调用', type: 4 }
      ],
      showDialog: false
    }
  },
  components: {
    MaterialContent,
    ChangeSendTimeDialog
  },
  methods: {
    onHandleCheckModeItem(type) {
      this.form.type = type
    }
  },
}
</script>
<style lang="scss" scoped>
.template-main {
  height: calc(100vh - 48px);
  overflow: auto;
  position: relative;

  .create-template-wrap {
    margin: 12px 12px 76px;

    .config-box {
      margin: 0 auto;
      width: 1200px;
      display: flex;
      flex-direction: column;

      .config-settig-card {
        background: #ffffff;
        margin-top: 12px;
        flex: 1 1;
        text-align: left;
        text-align: initial;
        color: rgba(0, 0, 0, 0.85);
        border-radius: 4px;
        background: #fff;
        font-size: 14px;

        .card-head {
          display: flex;
          justify-content: space-between;
          align-items: center;
          border-bottom: 1px solid #e9e9e9;

          .card-title {
            padding: 16px;
            font-weight: 600;
            color: rgba(0, 0, 0, 0.85);
          }
        }

        .card-body {
          padding: 24px;

          .mode-type-list {
            display: grid;
            grid-template-columns: 210px 210px 210px 210px;
            column-gap: 8px;

            .mode-item {
              display: flex;
              flex-direction: column;
              align-items: center;
              justify-content: center;
              width: 210px;
              height: 136px;
              background: #fff;
              border-radius: 2px;
              border: 1px solid #e9e9e9;
              text-align: center;
              cursor: pointer;
              &.active {
                box-shadow: 0 2px 8px 0 rgba(0,0,0,.1);
                border: 1px solid #3070ff;
              }

              .type-icon {
                width: 40px;
                height: 40px;
                background: #ebf2ff;
                border-radius: 4px;
                display: inline-flex;
                align-items: center;
                font-size: 14px;
                justify-content: center;
              }

              .type-title {
                font-size: 14px;
                font-weight: 400;
                color: rgba(0, 0, 0, .85);
                line-height: 20px;
                margin: 12px 0 4px;
              }

              .type-context {
                font-size: 12px;
                font-weight: 400;
                color: rgba(0, 0, 0, .45);
                line-height: 20px;
                margin-bottom: 0;
              }
            }
          }

          .plan-container {
            min-height: 500px;
            border: 1px solid #e9e9e9;
            display: flex;
            height: 100%;

            .plan-left {
              width: 200px;
              border-right: 1px solid #e9e9e9;

              .plus-btn {
                width: 100%;
                height: 40px;
              }

              .sop-dov-item {
                display: flex;
                align-items: center;
                justify-content: space-between;
                color: #666;
                height: 32px;
                margin: 8px 0;
                padding-left: 8px;
                padding-right: 5px;
                border-radius: 2px;
                cursor: pointer;
                transition: all .3s;
                margin: 8px 12px;

                &.active {
                  background: #ebf2ff;
                }

                &:hover {
                  .btns {
                    display: flex;
                  }
                }

                .btns {
                  display: none;
                  align-items: center;
                  gap: 4px;
                }
              }
            }

            .plan-right {
              flex: 1 1;

              .plan-right-top {
                color: rgba(0, 0, 0, .85);
                font-weight: 500;
                font-size: 16px;
                background: #f9f9f9;
                border-bottom: 1px solid #e9e9e9;
                border-radius: 4px 4px 0 0;
                padding: 12px;
                font-size: 14px;
                line-height: 22px;

                .top-flex-rows {
                  display: flex;
                  align-items: center;
                  gap: 8px;
                }
                .top-flex-column {
                  ::v-deep .el-radio-group {
                    display: flex;
                    flex-direction: column;
                    justify-content: center;
                    gap: 8px;
                    .radio-item {
                      display: flex;
                      align-items: center;
                      gap: 8px;
                    }
                    .el-radio {
                      display: flex;
                      align-items: center;
                      font-size: 14px;
                      .el-radio__input {
                        margin-top: 4px;
                      }
                    }
                    .el-radio__input.is-checked + .el-radio__label {
                      color: rgba(0, 0, 0, .65) !important;
                      font-size: 14px;
                    }
                  }
                }
              }
              .material-body {
                padding: 20px;
              }
            }
          }
        }
      }
    }
  }
}
</style>